#! -*- coding:utf-8 -*-
from django.conf import settings

from common import orm, ArmoryOrm
from common.utils.types import Enum

metis_orm = ArmoryOrm()
metis_orm.init_conf(settings.METIS_MYSQL_CONF)

M_TRANSACTION_TYPE = Enum({
    "FROZEN": (1L, u"out"),
    "FROZEN_REVERSE": (2L, u"reverse out"),
    "UNFREEZE": (3L, u"in")
})

PLATFORM_TYPE = Enum({
    "WITCH": (0L, u"witch"),
    "METIS": (1L, u"metis"),
})

MAP_GAME_ID = {
    1005: 5,
    1006: 6,
    1009: 9,
    5500: 5500,
    5501: 5501,
    5502: 5502,
    5503: 5503,
    5504: 5504,
    5600: 5600,
}


class ThirdBalance(orm.Model):
    __tablename__ = "metis_balance"
    id = orm.Column(orm.BigInteger, primary_key=True, autoincrement=True)
    user_id = orm.Column(orm.BigInteger)
    accu_balance = orm.Column(orm.BigInteger, default=0)
    last_platform = orm.Column(orm.Integer, default=0)
    last_balance = orm.Column(orm.BigInteger, default=0)
    frozen_status = orm.Column(orm.Boolean, default=False)
    created_at = orm.Column(orm.DATETIME)
    updated_at = orm.Column(orm.DATETIME)


class ThirdTransaction(orm.Model):
    __tablename__ = "metis_transaction"
    id = orm.Column(orm.BigInteger, primary_key=True, autoincrement=True)
    user_id = orm.Column(orm.BigInteger)
    platform = orm.Column(orm.Integer)  # 平台 PLATFORM_TYPE
    type = orm.Column(orm.Integer)  # 转入/转出
    balance = orm.Column(orm.BigInteger)  # 账户余额-累计
    withdraw = orm.Column(orm.BigInteger)  # 可用提现额度-累计
    accu_balance = orm.Column(orm.BigInteger)  # 累計余额
    accu_withdraw = orm.Column(orm.BigInteger)  # 累計提現
    curr_balance = orm.Column(orm.BigInteger)  # 当前余额
    curr_withdraw = orm.Column(orm.BigInteger)  # 当前可提现
    ref_id = orm.Column(orm.VARCHAR)  # 唯一订单号
    checked = orm.Column(orm.Boolean, default=False)  # 是否已和metis对账
    created_at = orm.Column(orm.DATETIME)
    updated_at = orm.Column(orm.DATETIME)


class ThirdWithdrawTransactionLog(orm.Model):
    __tablename__ = "metis_withdraw_trans_log"
    id = orm.Column(orm.BigInteger, primary_key=True, autoincrement=True)
    user_id = orm.Column(orm.BigInteger)
    platform = orm.Column(orm.Integer)  # 平台 PLATFORM_TYPE
    amount = orm.Column(orm.BigInteger)
    ref_id = orm.Column(orm.VARCHAR)
    checked = orm.Column(orm.Boolean, default=False)  # 是否已和metis对账
    created_at = orm.Column(orm.DATETIME)
    updated_at = orm.Column(orm.DATETIME)


class MetisPlatformUser(metis_orm.Model):
    __tablename__ = "users"
    id = orm.Column(orm.BigInteger, primary_key=True)
    subsidiary_user_id = orm.Column(orm.VARCHAR)


class MetisPlatformLogBet(metis_orm.Model):
    __tablename__ = "log_bet"
    id = orm.Column(orm.BigInteger, primary_key=True)
    user_id = orm.Column(orm.BigInteger)
    bet_amount = orm.Column(orm.FLOAT)  # 押注金额
    bet_result = orm.Column(orm.FLOAT)  # 返还金额
    status = orm.Column(orm.Integer)  # 1 为有效投注
    bet_type = orm.Column(orm.Integer)  # 1 为有效投注
    created_at = orm.Column(orm.DATETIME)
